/*
* ============================================================================
* 功能描述 ：蜂鸣器驱动配置
* 作者       ：ggls
* 创建日期 ：2024.06.05
* ----------------------------------------------------------------------------
* 更新历史 ：
*	日期 　　- 修改者   : 更新内容描述
*
* ============================================================================
*/


#include "main.h"

/*
val:分贝值，0x1230为60分贝           0x1070为80分贝     0x12a0为40分贝
*/
void BUZZER_Config(int val)
{
	/*
	(1)配置蜂鸣器时钟
	*/
//	BUZ_ConfigBuzzer(BUZ_CKS_32,188);			//Fsys=24Mhz，Fbuz = Fsys/(2*32*200) =2khz
//	BUZ_ConfigBuzzer(BUZ_CKS_32,200);

	/*
	(2)配置蜂鸣器输出IO
	*/	
//	GPIO_SET_MUX_MODE(P13CFG,GPIO_MUX_BEEP);
	
		
	//设置EPWM运行模式
		EPWM_ConfigRunMode(EPWM_WFG_COMPLEMENTARY|EPWM_OC_INDEPENDENT|EPWM_OCU_SYMMETRIC|EPWM_COUNT_UP_DOWN); //互补模式+输出独立模式+对称计数模式+上下计数(中心对齐)模式
		//设置EPWM运行时钟	
		EPWM_ConfigChannelClk(EPWM0, EPWM_CLK_DIV_1);		
//		EPWM_ConfigChannelClk(EPWM2, EPWM_CLK_DIV_1);
//		EPWM_ConfigChannelClk(EPWM4, EPWM_CLK_DIV_1);
		//设置EPWM 周期以及占空比	
		EPWM_ConfigChannelPeriod(EPWM0, 0x12C0);
//		EPWM_ConfigChannelPeriod(EPWM2, 0x12C0);
//		EPWM_ConfigChannelPeriod(EPWM4, 0x12C0);
	
	#if (1)
		EPWM_ConfigChannelSymDuty(EPWM0, val);   // 0x1230为60分贝     0x1070为80分贝     0x12a0为40分贝
//		EPWM_ConfigChannelSymDuty(EPWM2, 0x0960);
//		EPWM_ConfigChannelSymDuty(EPWM4, 0x0960);
	#elif (0)
		EPWM_ConfigChannelSymDuty(EPWM0, 0);
		EPWM_ConfigChannelSymDuty(EPWM2, 0);
		EPWM_ConfigChannelSymDuty(EPWM4, 0);
	#else 
		EPWM_ConfigChannelSymDuty(EPWM0, 0xFFFF);
		EPWM_ConfigChannelSymDuty(EPWM2, 0xFFFF);
		EPWM_ConfigChannelSymDuty(EPWM4, 0xFFFF);
	#endif
	
		//设置EPWM的加载方式为自动加载
		EPWM_EnableAutoLoadMode(EPWM_CH_0_MSK);
		//设置EPWM的输出极性
		EPWM_DisableReverseOutput(EPWM_CH_0_MSK); //关闭反向输出
		//设置EPWM输出
		EPWM_EnableOutput(EPWM_CH_0_MSK); 	//开启输出
		//设置EPWM死区
		EPWM_DisableDeadZone(EPWM0);
//		EPWM_DisableDeadZone(EPWM2);
//		EPWM_DisableDeadZone(EPWM4);
		//设置EPWM中断
//		EPWM_EnableZeroInt(EPWM_CH_0_MSK);				//开启EPWM零点中断
//		EPWM_AllIntEnable();							//开启EPWM总中断
//		IRQ_SET_PRIORITY(IRQ_PWM,IRQ_PRIORITY_LOW);
		IRQ_ALL_ENABLE();								//开启总中断
	
		//设置EPWM输出IO复用
		GPIO_SET_MUX_MODE(P13CFG, GPIO_MUX_PG0);
		
		//开启EPWM

}

